﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {
    public class TestKeyframeSequenceT {
        [Fact]
        public void Test_New1 () {
            var kseq = new KeyframeSequence<int> (4, 3);

            Assert.Equal (4, kseq.KeyframeCount);
            Assert.Equal (3, kseq.ComponentCount);
            Assert.Equal (0, kseq.ValidRangeStart);
            Assert.Equal (0, kseq.ValidRangeEnd);
            Assert.Equal (0, kseq.Duration);
        }

        [Fact]
        public void Test_SetKeyframe () {
            var kseq = new KeyframeSequence<float> (2, 3);

            kseq.SetKeyframe (0, 100, 100, 200, 300);
            kseq.SetKeyframe (1, 101, 101, 201, 301);

            var key0 = kseq.GetKeyframe (0);
            Assert.Equal (100, key0.Time);
            Assert.Equal (100, key0.Value[0]);
            Assert.Equal (200, key0.Value[1]);
            Assert.Equal (300, key0.Value[2]);

            var key1 = kseq.GetKeyframe (1);
            Assert.Equal (101, key1.Time);
            Assert.Equal (101, key1.Value[0]);
            Assert.Equal (201, key1.Value[1]);
            Assert.Equal (301, key1.Value[2]);
        }

        [Fact]
        public void Test_SetValidRange () {
            var kseq = new KeyframeSequence<float> (4, 3);

            kseq.SetValidRange (1, 3);

            Assert.Equal (1, kseq.ValidRangeStart);
            Assert.Equal (3, kseq.ValidRangeEnd);
        }

        [Fact]
        public void Test_SetDuration(){
            var kseq = new KeyframeSequence<float> (4, 3);
            kseq.SetDuration (100);

            Assert.Equal (100, kseq.Duration);
        }

        [Fact]
        public void Test_Indexer () {
            var kseq = new KeyframeSequence<byte> (2, 1);

            kseq.SetKeyframe (0, 100, 200);
            kseq.SetKeyframe (1, 101, 201);

            Assert.Equal (100, kseq[0].Time);
            Assert.Equal (200, kseq[0].Value[0]);
            Assert.Equal (101, kseq[1].Time);
            Assert.Equal (201, kseq[1].Value[0]);
        }

        [Fact]
        public void Test_Enumerator () {
            var kseq = new KeyframeSequence<float> (3, 1);

            kseq.SetKeyframe (0, 100, 200);
            kseq.SetKeyframe (1, 101, 201);
            kseq.SetKeyframe (2, 102, 202);

            var sum1 = kseq.Sum (x => x.Time);
            var sum2 = kseq.Sum (x => x.Value[0]);

            Assert.Equal (303, sum1);
            Assert.Equal (603, sum2);
        }

    }
}
